<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<jsp:include page="../../fragments/header.jsp">
	<jsp:param name="title" value="Customer Information" />
</jsp:include>

<ol class="progtrckr">
	<li class="progtrckr-done">Shopping Cart</li>
	<li class="progtrckr-todo">Customer Info</li>
	<li class="progtrckr-todo">Payment Options</li>
	<li class="progtrckr-todo">Finalizing Order</li>
</ol>
<br />
<br />

<table cellspacing="10px" cellpadding="10px">
	<tr>
		<td style="border-style: solid;">
			<form method="post" action="customer_info">
				<input type="hidden" name="operation" value="search">
				<input type="text" name="customerEmail" style="width: 100px;" />
				<input type="Submit" value="Search by mail" />
			</form>
		</td>
		<td style="border-style: solid;">
			<form method="post" action="customer_new">
				<input type="hidden" name="operation" value="add">
				<input type="Submit" value="Add New Customer" />
			</form>
		</td>
	</tr>
</table>

<c:choose>
	<c:when test="${operation == 'search'}">
		<c:choose>
			<c:when test="${empty searchResult}">
				There are no customers with this mail
			</c:when>
			<c:otherwise>
			<form method="post" action="${pageContext.request.contextPath}/update_customer" name="allCustomers">
				<table class="table table-hover">
					<thead>
						<tr>
							<th></th>
							<th>NAME</th>
							<th>EMAIL</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${searchResult}" var="customer">
							<tr>
								<td><input type="radio" name="selectedCustomer" value="${customer.id}" /></td>
								<td><a href="${pageContext.request.contextPath}/customer_details?id=${customer.id}">${customer.firstName} ${customer.lastName}</a></td>
								<td>${customer.email}</td>	
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<!-- 
				<script type="text/javascript">
					function selectAction(action){
						document.allCustomers.action=action;
						document.allCustomers.submit();
					}
				</script>
				<input type="button" value="Select" onClick="selectAction('updateCustomer')" />
				-->
				<input type="submit" class="btn btn-default btn-block" value="Select" />
				</form>	
			</c:otherwise>
		</c:choose>
	</c:when>
	<c:when test="${updateOperation == 'true'}">
		<table class="table table-hover">
			<thead>
				<tr>
					<th>NAME</th>
					<th>EMAIL</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>${customer.firstName} ${customer.lastName}</td>
					<td>${customer.email}</td>	
				</tr>
			</tbody>
		</table>
	</c:when>
</c:choose>
<br />
<br />
<form action="${pageContext.request.contextPath}/shopping_cart">
	<button class="btn btn-default">
		<b>Back</b>
	</button>
</form>
<form action="${pageContext.request.contextPath}/cancel_order">
	<button class="btn btn-default">
		<b>Cancel Order</b>
	</button>
</form>
<c:if test="${enableNextStep == 'true'}">
<form action="${pageContext.request.contextPath}/credit_card_info">
	<button class="btn btn-default">
		<b>Next</b>
	</button>
</form>
</c:if>

<jsp:include page="../../fragments/footer.jsp" />